package com.ruoyi.piliangruku.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.piliangruku.domain.PiliangRuku;
import com.ruoyi.piliangruku.domain.PiliangRuku2;
import com.ruoyi.piliangruku.mapper.PiliangRukuMapper;
import com.ruoyi.piliangruku.service.IPiliangRukuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 批量入库Service业务层处理
 * 
 * @author beilian
 * @date 2023-01-10
 */
@Service
public class PiliangRukuServiceImpl implements IPiliangRukuService 
{
    @Autowired
    private PiliangRukuMapper piliangRukuMapper;

    /**
     * 查询批量入库
     * 
     * @param id 批量入库主键
     * @return 批量入库
     */
    @Override
    public PiliangRuku selectPiliangRukuById(Long id)
    {
        return piliangRukuMapper.selectPiliangRukuById(id);
    }

    @Override
    public String selectGouhuoDanhaoByLastOne() {
        return piliangRukuMapper.selectGouhuoDanhaoByLastOne();
    }

    /**
     * 查询批量入库列表
     * 
     * @param piliangRuku 批量入库
     * @return 批量入库
     */
    @Override
    public List<PiliangRuku> selectPiliangRukuList(PiliangRuku piliangRuku)
    {
        return piliangRukuMapper.selectPiliangRukuList(piliangRuku);
    }

    /**
     * 新增批量入库
     * 
     * @param piliangRuku 批量入库
     * @return 结果
     */
    @Override
    public int insertPiliangRuku(PiliangRuku piliangRuku)
    {
        return piliangRukuMapper.insertPiliangRuku(piliangRuku);
    }

    /**
     * 修改批量入库
     * 
     * @param piliangRuku 批量入库
     * @return 结果
     */
    @Override
    public int updatePiliangRuku(PiliangRuku piliangRuku)
    {
        return piliangRukuMapper.updatePiliangRuku(piliangRuku);
    }

    /**
     * 批量删除批量入库
     * 
     * @param ids 需要删除的批量入库主键
     * @return 结果
     */
    @Override
    public int deletePiliangRukuByIds(String ids)
    {
        return piliangRukuMapper.deletePiliangRukuByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除批量入库信息
     * 
     * @param id 批量入库主键
     * @return 结果
     */
    @Override
    public int deletePiliangRukuById(Long id)
    {
        return piliangRukuMapper.deletePiliangRukuById(id);
    }

    @Override
    public void deletePiliangRukuByGgouhuoDanhao(String gouhuoDanhao) {
        piliangRukuMapper.deletePiliangRukuByGgouhuoDanhao(gouhuoDanhao);
    }

    @Override
    public List<PiliangRuku2> selectPiliangRukuListAndQuanXian(PiliangRuku piliangRuku) {
        List<PiliangRuku> shangpinxinxiList = piliangRukuMapper.selectPiliangRukuList(piliangRuku);
        List<PiliangRuku2> shangpinxinxi2List = new ArrayList<>();
        for (PiliangRuku s: shangpinxinxiList
        ) {
            PiliangRuku2 piliangRuku2 = new PiliangRuku2();
            piliangRuku2.setGouhuoDate(s.getGouhuoDate());
            piliangRuku2.setPaymentMethod(s.getPaymentMethod());
            piliangRuku2.setGouhuoJingshouren(s.getGouhuoJingshouren());
            piliangRuku2.setGouhuoCangku(s.getGouhuoCangku());
            piliangRuku2.setGoodId(s.getGoodId());
            piliangRuku2.setShangpinLeibie(s.getShangpinLeibie());
            piliangRuku2.setGoodName(s.getGoodName());
            piliangRuku2.setGoodGuige(s.getGoodGuige());
            piliangRuku2.setShuliang(s.getShuliang());
            piliangRuku2.setDijia(s.getDijia());
            piliangRuku2.setJiner(s.getJiner());
            shangpinxinxi2List.add(piliangRuku2);
        }
        return shangpinxinxi2List;
    }
}
